﻿<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="Generator" content="EditPlus®">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta name="renderer" content="webkit">
    <title>用户注册</title>
    <link rel="shortcut icon" type="image/x-icon" href="~/theme/icon/favicon.ico">
    <link rel="stylesheet" type="text/css" href="~/theme/css/base.css">
    <link rel="stylesheet" type="text/css" href="~/theme/css/login.css">
</head>
<body>

    <!--- header begin-->
    <header id="pc-header">
        <div class="login-header" style="padding-bottom:0">
            <div><h1><a href="index.html"><img src="~/theme/icon/logo.png"></a></h1></div>
        </div>
    </header>
    <!-- header End -->



    <section id="login-content">
        <div class="login-centre">
            <div class="login-switch clearfix">
                <p class="fr">我已经注册，现在就 <a href="login.html">登录</a></p>
            </div>
            <div class="login-back">
                <div class="H-over">
                    <form>
                        <div class="login-input">
                            <label><i class="heart">*</i>用户名：</label>
                            <input type="text" class="list-input1" id="username" name="info[username]" placeholder="">
                        </div>
                        <div class="login-input">
                            <label><i class="heart">*</i>请设置密码：</label>
                            <input type="text" class="list-input" id="password" name="info[password]" placeholder="">
                        </div>
                        <div class="login-input">
                            <label><i class="heart">*</i>请确认密码：</label>
                            <input type="text" class="list-input" id="repassword" name="info[password]" placeholder="">
                        </div>
                        <div class="login-input">
                            <label><i class="heart">*</i>手机号：</label>
                            <input type="text" class="list-iphone" id="tel" name="info[password]" placeholder="">
                            <a href="#" id="GetCode" class="obtain">获取短信验证码</a>
                        </div>
                        <div class="login-input">
                            <label><i class="heart">*</i>短信验证码：</label>
                            <input type="text" class="list-notes" id="yan" name="info[password]" placeholder="">
                        </div>
                        <div class="item-ifo">
                            <input type="checkbox" onClick="agreeonProtocol();" id="readme" checked="checked" class="checkbox">
                            <label for="protocol">我已阅读并同意<a id="protocol" class="blue" href="#">《悦商城用户协议》</a></label>
                            <span class="clr"></span>
                        </div>
                        <div class="login-button">
                            <a href="#" id="btnRe">立即注册</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>

    <!--- footer begin-->
    <footer id="footer">
        <div class="containers">
            <div class="w" style="padding-top:30px">
                <div id="footer-2013">
                    <div class="links">
                        <a href="">关于我们</a>
                        |
                        <a href="">联系我们</a>
                        |
                        <a href="">人才招聘</a>
                        |
                        <a href="">商家入驻</a>
                        |
                        <a href="">广告服务</a>
                        |
                        <a href="">手机京东</a>
                        |
                        <a href="">友情链接</a>
                        |
                        <a href="">销售联盟</a>
                        |
                        <a href="">English site</a>
                    </div>
                    <div style="padding-left:10px">
                        <p style="padding-top:10px; padding-bottom:10px; color:#999">网络文化经营许可证：浙网文[2013]0268-027号| 增值电信业务经营许可证：浙B2-20080224-1</p>
                        <p style="padding-bottom:10px; color:#999">信息网络传播视听节目许可证：1109364号 | 互联网违法和不良信息举报电话:0571-81683755</p>
                    </div>
                </div>
            </div>

        </div>
    </footer>
    <!-- footer End -->
</body>
</html>
<script type="text/javascript">
    var ckname = false;
    var ckpwd = false;
    var ckrepwd = false;
    var ckphone = false;
    var ckcode = false;
    //工厂函数
    $(function () {
        //点击获取验证
        $("#GetCode").click(function () {
            var tel = $("#tel").val();
            $.ajax({
                url: "/SMSCode/GetCode?phone=" + tel,
                type: "post",
                success: function (result) {
                    if (result.Success) {
                        alert("获取成功");
                        IntervalSMS();
                    }
                    else {
                        alert("获取失败");
                    }
                }
            })
        })
        //注册按钮
        $("#btnRe").click(function () {

            if (ckname == true && ckphone == true && ckrepwd == true && ckpwd == true) {
                var SMSInfo = {};
                SMSInfo.TelPhone = $("#tel").val();
                SMSInfo.Code = $("#yan").val();
                $.ajax({
                    url: "/SMSCode/SelCodePhone",
                    type: "post",
                    data: SMSInfo,
                    success: function (result) {
                        if (result.Success) {
                            reg();
                        }
                        else {
                            alert("短信验证码不存在");
                            return;
                        }
                    }
                })
            }
            else {
                alert("信息验证未通过无法注册成功");
            }
        })
        $("#username").blur(Checkname);
        $("#password").blur(Checkpwd);
        $("#repassword").blur(Checkrepwd);
        $("#tel").blur(Checktel);
    });
    //查询电话和验证码是否正确
    function reg() {
        var userInfo = {};
        userInfo.UserName = $("#username").val();
        userInfo.Pwd = $("#password").val();
        userInfo.Phone = $("#tel").val();
        $.ajax({
            url: "/Register/SaveUserInfo",
            data: userInfo,
            type: "post",
            success: function (result) {
                if (result.Success) {
                    alert("注册成功");
                }
                else {
                    alert("注册失败");
                }
            }
        })
    }
    //短信验证计时器
    function IntervalSMS() {

        $("#GetCode").attr("disable", "disabled");
        $("#GetCode").css("color", "red");

        var time = 30;
        $("#GetCode").val(time + " S后重新获取验证码");

        var timer = setInterval(function () {
            if (time > 0) {
                time--;
                $("#GetCode").val(time + " S后重新获取验证码");
            }
            else {
                $("#GetCode").removeAttr("disable").css("color", "black");
                $("#GetCode").val("重新获取验证码");
                clearInterval(timer);
            }
        }, 1000)
    }
    //验证电话号码
    function Checktel() {
        var tel = $("#tel").val();
        var teltxt = $("#teltxt");
        if (tel.length == 0) {
            teltxt.html("号码不能为空");
            teltxt.css("color", "red");
            ckphone = false;
            return;
        }
        var regtel = /^1[0-9]{10}$/;
        if (regtel.test(tel) == false) {
            teltxt.html("号码必须是十一位");
            teltxt.css("color", "red");
            ckphone = false;
            return;
        }
        var userInfo = {};
        userInfo.Phone = tel;
        $.ajax({
            url: "/Register/SelUserPhone",
            data: userInfo,
            type: "post",
            success: function (result) {
                if (result.Success) {
                    teltxt.html("电话号码已经存在");
                    teltxt.css("color", "red");
                    ckphone = false;
                    return;
                }
                else {
                    teltxt.html("√");
                    teltxt.css("color", "green");
                    ckphone = true;
                    return;
                }
            }
        })
    }

    //验证第二次密码
    function Checkrepwd() {
        var repwd = $("#repassword").val();
        var pwd = $("#password").val();
        var repwdtxt = $("#repwdtxt");
        if (pwd != repwd) {
            repwdtxt.html("两次密码输入不一致");
            repwdtxt.css("color", "red");
            ckrepwd = false;
            return;
        }
        repwdtxt.html("√");
        repwdtxt.css("color", "green");
        ckrepwd = true;
        return;
    }

    //验证密码
    function Checkpwd() {
        var pwd = $("#password").val();
        var pwdtxt = $("#pwdtxt");
        if (pwd.length == 0) {
            pwdtxt.html("密码不能为空");
            pwdtxt.css("color", "red");
            ckpwd = false;
            return;
        }
        var regpwd = /^[a-zA-Z0-9]{6,10}$/;
        if (regpwd.test(pwd) == false) {
            pwdtxt.html("密码不符合格式");
            pwdtxt.css("color", "red");
            ckpwd = false;
            return;
        }
        pwdtxt.html("√");
        pwdtxt.css("color", "green");
        ckpwd = true;
    }

    //验证用户名
    function Checkname() {
        var name = $("#username").val();
        var nametxt = $("#nametxt");
        if (name.length == 0) {
            nametxt.html("用户名不能为空");
            nametxt.css("color", "red");
            ckname = false;
            return;
        }
        var userInfo = {};
        userInfo.UserName = name;
        $.ajax({
            url: "/Register/SelUserName",
            data: userInfo,
            type: "post",
            success: function (result) {
                if (result.Success) {
                    nametxt.html("用户名已经存在");
                    nametxt.css("color", "red");
                    ckname = false;
                    return;
                }
                else {
                    nametxt.html("√");
                    nametxt.css("color", "green");
                    ckname = true;
                    return;
                }
            }
        })
    }
</script>